#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File facebook_spider
 * Created by leixu on 2017/11/23
 * IDE PyCharm
'''
from luobo.spider import patch_gevent

# 如果执行的是远程方式需要 执行如下语句
# 如果是本地执行的则需要   注释如下语句
#patch_gevent()

from luobo.spider.base_spider import ScriptRunMode
from luobo.spider.spiders import SeleniumBaseSpider, AsyncCrawlerRuler


class TestSpider(SeleniumBaseSpider):
    def __init__(self):
        super().__init__()
        self.RUN_MODE = ScriptRunMode.LOCAL
        self.setting.PARALLEL_WORKER_NUMBERS = 1

    def start_crawler(self):
        ruler = AsyncCrawlerRuler()
        ruler.load_script("./script/facebook_script.py")
        ruler.rule_index = 4
        self.crawler_feeder.add(ruler, self.callback)

    def callback(self, response):
        print(response)

    def add_params(self):
        args = [1, 2, 3, 4, 5, 6, 7]

        self.params_deliver.add_params(*args)

    def print_state(self):
        print(self.spider_state)


if __name__ == "__main__":
    b = TestSpider()
    b.start_crawl()
